import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { CommonService } from 'src/app/service/common/common.service';

@Component({
  selector: 'app-common-use-func',
  templateUrl: './common-use-func.component.html',
  styleUrls: ['./common-use-func.component.scss']
})
export class CommonUseFuncComponent implements OnInit {

  constructor(
    private common: CommonService,
    private router: Router
  ) { }

  commonFuncData: any = []
  ngOnInit(): void {
    this.getCommonFuncs()
  }
  getCommonFuncs(){
    this.common._getCommonFuncs().subscribe({
      next: (value) => {
        this.commonFuncData = value
      },
      error: (err) => {
        
      },
    })
  }

  commonUseFunc = {
    '水管报漏': '我的用水'
  }
  goNav(item: any){
    console.log(item)
    this.router.navigate([item.webPath])
    let webPath = item.webPath
    if(webPath.indexOf('cancel-user') > -1 || webPath.indexOf('base-form') > -1){
      webPath = '/base-form'
      const queryParams = {
        id: item.funcTypeId,
        name: item.funcName,
        isDetail: true,
        sortName: this.commonUseFunc[item.funcName],
        funcCode: item.funcCode,
        path: item.webPath
      }

      this.router.navigate([webPath], { queryParams })
      return
    }else{
      const queryParams = {
        name: item.funcName,
        funcCode: item.funcCode,
      }

      this.router.navigate([webPath], { queryParams })
      return
    }
  }

}
